import request from '@/utils/request'

export function getStatistics() {
  // 获取当前日期
  const today = new Date().toISOString().split('T')[0];
  
  return Promise.all([
    // 获取注册人数
    request({
      url: '/educenter/member/countTotalMembers',
      method: 'get'
    }),
    // 获取讲师总数
    request({
      url: '/eduservice/teacher/countTotalTeachers',
      method: 'get'
    }),
    // 获取课程总数
    request({
      url: '/eduservice/course/countTotalCourses',
      method: 'get'
    }),
    // 获取今日订单数
    request({
      url: `/staservice/staorder/orderCount/${today}`,
      method: 'post'
    })
  ]).then(responses => {
    return {
      data: {
        stats: {
          registerNum: responses[0].data.totalMembers || 0,
          teacherNum: responses[1].data.totalTeachers || 0,
          courseNum: responses[2].data.totalCourses || 0,
          orderNum: responses[3].data.countOrder || 0
        }
      }
    };
  });
}

export function getHotCourses() {
  return request({
    url: '/eduservice/course/pageCourseCondition/1/4',
    method: 'post',
    data: {
      status: 'Normal',
      sort: 'viewCount'
    }
  }).then(response => {
    return {
      data: {
        courses: response.data.rows || []
      }
    };
  });
}